package com.example.demo.config;

import com.example.demo.condition.SystemCondition;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

import javax.servlet.MultipartConfigElement;

/**
 * Created by lyc on 2019/6/7.
 * 解决线上隔一段时间 临时文件上传 不行指定 目录
 */
@Configuration
public class MultipartConfig {

    /**
     * 文件上传临时路径
     */
    @Bean
    @Conditional(SystemCondition.class)
    MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //注意目录需要读写权限
        factory.setLocation("/home/temp");
        return factory.createMultipartConfig();
    }
}
